/**
 * created by 小卷毛, 2020-05-21 021
 * Copyright (c) 2020, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.zhiyou.aifeng.utils

import com.luck.picture.lib.PictureSelectionModel
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.listener.OnResultCallbackListener

fun PictureSelectionModel.callback(
    listener: _OnResultCallbackListener<LocalMedia>.() -> Unit
) {
    val mListener = _OnResultCallbackListener<LocalMedia>()
    mListener.listener()
    forResult(mListener)
}

@Suppress("ClassName")
open class _OnResultCallbackListener<T : LocalMedia> : OnResultCallbackListener<T> {

    private var _onResult: ((MutableList<T>) -> Unit)? = null
    private var _onCancel: (() -> Unit)? = null

    fun onResult(listener: (MutableList<T>) -> Unit) {
        _onResult = listener
    }

    fun onCancel(listener: () -> Unit) {
        _onCancel = listener
    }

    override fun onResult(result: MutableList<T>) {
        _onResult?.invoke(result)
    }

    override fun onCancel() {
        _onCancel?.invoke()
    }

}